package sample;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.Random;
import java.util.Random;
public class Magic {
        Random random = new Random();
        Integer x = random.nextInt(Yard.COL*Yard.BLOCK_SIZE)/10*10+10;
        Integer y = random.nextInt(Yard.ROW*Yard.BLOCK_SIZE)/10*10+10;
        int i = 0;
        public void draw(Canvas canvas) {
            GraphicsContext gc = canvas.getGraphicsContext2D();
            if(i%2==0) {
                gc.setFill(Color.PURPLE);
                i++;
            }
            else {
                gc.setFill(Color.GREEN);
                i++;
            }
            gc.fillRect(x/10*10,y/10*10,Yard.BLOCK_SIZE,Yard.BLOCK_SIZE);
        }
        public  void reAppear(int score){
               new Thread(new nThread(score)).start();
        }
        public class nThread extends Thread{

            int score;
            public nThread(int score){
                this.score = score;
            }
            public void run(){

                    x = -10;
                    y = -10;
                    try {
                        Thread.sleep(20000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    x= new Random().nextInt((400 - 10 + 1) + 10) / 10 * 10;
                    y = new Random().nextInt((400- 10 + 1) + 10) / 10 * 10;
                }





        }
    }

